package com.sxfq.loansupermarket.backsystem.modular.report.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.report.dao.CashDailyReportDao;
import com.sxfq.loansupermarket.backsystem.modular.report.entity.CashDailyReportInfo;
import com.sxfq.loansupermarket.backsystem.modular.report.entity.SearchCashDailyReportInfo;
import com.sxfq.loansupermarket.backsystem.modular.report.service.ICashDailyReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CashDailyReportServiceImpl implements ICashDailyReportService {

    @Autowired
    private CashDailyReportDao dao;

    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<CashDailyReportInfo> selectPageListByQueryGetMap(Page<CashDailyReportInfo> page, SearchCashDailyReportInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "recharge_info";
        params.put("tableName", tableName);
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPage(page, params);
    }

    @Override
    public List<CashDailyReportInfo> cashDailyReportExport(SearchCashDailyReportInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "recharge_info";
        params.put("tableName", tableName);
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.cashDailyReportExport(params);
    }

    public int getQueryPagesCount(Page<CashDailyReportInfo> page, SearchCashDailyReportInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "recharge_info";
        params.put("tableName", tableName);
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesCount(page, params);
    }

}
